
/*
    Software License

    Copyright (C) 2021-05-24  Xoronos

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*
    Liabilities

    The software is provided "AS IS" without any warranty of any kind, either expressed,
    implied, or statutory, including, but not limited to, any warranty that the software
    will conform to specifications, any implied warranties of merchantability, fitness
    for a particular purpose, and freedom from infringement, and any warranty that the
    documentation will conform to the software, or any warranty that the software will
    be error free.

    In no event shall Xoronos be liable for any damages, including, but not limited to,
    direct, indirect, special or consequential damages, arising out of, resulting from,
    or in any way connected with this software, whether or not based upon warranty,
    contract, tort, or otherwise, whether or not injury was sustained by persons or
    property or otherwise, and whether or not loss was sustained from, or arose out of
    the results of, or use of, the software or services provided hereunder.

    To request the provided software under a different license you can contact us at
    support@xoronos.com
*/

#ifndef XRN_TYPEDEF_H
#define XRN_TYPEDEF_H

#include <stdio.h>
#include <stdint.h>

#define XRN_BUFFER_ENC_CHECK_SIZE 128
#define XRN_BUFF_SIZE 256
#define XRN_ENC_PASS_BUFF_SIZE 256
#define XBIT_TYPE bool

typedef struct xrn_log_t {

    FILE *err_fp;
    FILE *war_fp;
    FILE *not_fp;
    FILE *deb_fp;
    uint8_t err_en;
    uint8_t war_en;
    uint8_t not_en;
    uint8_t deb_en;

} xrn_log_t;

typedef struct xrn_crypto_lib_header_t {

    uint8_t encoding_guard[256];
    uint32_t magic_number;
    uint32_t version;
    uint32_t reserved_0;
    uint32_t reserved_1;
    uint8_t type;
    uint8_t state_size;
    uint8_t crc8;

} xrn_crypto_lib_header_t;

typedef enum {
    xgenesis = 0,
    xbase = 1,
    xvector = 2,
    xmatrix = 3,
    xmatrix_compressed = 4,
    xstart = 5,
    xmonomial_key = 6,
    xbinomial_key = 7,
    xpoint = 8,
    xhash = 9,
    xsignature_sym = 10,
    xsignature_asy = 11,
    xring_signature = 12,
    xcertificate_sym = 13,
    xcertificate_asy = 14,
    xmonomial_commitment = 15,
    xbinomial_commitment = 16,
    xmonomial_response = 17,
    xmonomial_proof = 18,
    xpolyvalent_proof = 19,
    xpolyvalent_key = 20,
    xmonovalent_key = 21,
    xchallenge = 22,
    xsolution = 23,
    xsym = 24,
    xasy = 25
} xrn_lib_xtype_t;

typedef enum {
    std_parameters = 0,
    xrn_parameters = 1,
    std_parameters_plus_password = 2,
    xrn_parameters_plus_password = 3,
    no_encoding = 4
} xrn_encoding_mode_t;

typedef enum {
    xrn_automatic = 0,
    xrn_manual = 1,
} xrn_check_initialization_mode_t;

typedef struct xrn_encoding_checks_t {
    uint8_t index;
    uint8_t buffer[XRN_BUFFER_ENC_CHECK_SIZE];
    uint8_t buffer_full;
    uint8_t check_running_error_en;
    uint8_t check_disparity_error_en;
    uint32_t max_consecutives_01s_threshold_error;
    uint32_t max_consecutives_01s_threshold_warning;
    uint32_t max_number_of_01s_threshold_error;
    uint32_t max_number_of_01s_threshold_warning;
    uint32_t count_1;
    uint32_t count_0;
    uint32_t count_consecutive_1;
    uint32_t count_consecutive_0;
    uint32_t max_consecutive_1;
    uint32_t max_consecutive_0;
} xrn_encoding_checks_t;

typedef struct xrn_encoding_param_t {
    uint8_t table[256];
    uint64_t prng_state[4];
    xrn_encoding_checks_t prob_checks;
} xrn_encoding_param_t;

typedef struct xrn_encoding_tmp_param_t {
    int i, j, k, ret, final_ret;
    uint8_t hidden_index_prng, hidden_index_input;
    uint8_t exposed_data_prng, hidden_data_input;
    uint8_t pseudo_random_seed;
    uint64_t t;
    uint8_t byte_tmp;
} xrn_encoding_tmp_param_t;

typedef struct xrn_encoding_settings_t {
    FILE *encoding_parameters_fp;
    xrn_encoding_mode_t mode;
    char password[XRN_ENC_PASS_BUFF_SIZE];
    uint16_t password_length;
    xrn_check_initialization_mode_t check_mode;
    uint8_t check_running_error_en;
    uint8_t check_disparity_error_en;
    uint32_t max_consecutives_01s_threshold_error;
    uint32_t max_consecutives_01s_threshold_warning;
    uint32_t max_number_of_01s_threshold_error;
    uint32_t max_number_of_01s_threshold_warning;
} xrn_encoding_settings_t;

typedef struct xrn_encoding_interface_t {
    xrn_encoding_param_t i_encoding_param;
    xrn_encoding_param_t o_encoding_param;
} xrn_encoding_interface_t;

typedef struct xrn_interface_settings_t {
    xrn_encoding_settings_t i_settings;
    xrn_encoding_settings_t o_settings;
} xrn_interface_settings_t;

#endif
